var api = require('../../utils/api.js');
//在使用的View中引入WxParse模块
var WxParse = require('../../wxParse/wxParse.js');

Page({
  data: {
    hidden: false,
    id: "",
    title: "",
    author:"",
    createTime:"",
    content: "",
    originalURL:""
  },
  onLoad: function (options) {
    var self = this;
    self.setData({
      id: options.id
    });
     this.fetchData({id:options.id});
  },

  fetchData: function (data) {
    var self = this;
    self.setData({
      hidden: false
    });

    wx.request({
      url: api.getBlog(data),
      dataType: "json",
      success: function (res) {

        self.setData({
          title: res.data.title,
          author: res.data.nickname,
          createTime : res.data.in_time,
          originalURL : res.data.original_url
        });

        WxParse.wxParse('content', 'md', res.data.content, self, 5);
        setTimeout(function () {
          self.setData({
            hidden: true
          });
        }, 300);
      }
    });
  },
    // 分享代码
  onShareAppMessage: function () {
    return {
      title: this.data.title + " - Java学习论坛",
      path: "/pages/index/blog?id="+this.data.id,
      success: function(res) {
        // 分享成功
      },
      fail: function(res) {
        // 分享失败
      }
    }
  }

})
